class Userinfo
  include Mongoid::Document
  include Mongoid::Timestamps
  include Mongoid::Geospatial

  field :name, type: String # 经营者姓名1
  field :idnumber, type: String #身份证号码1

  field :alipay, type: String #支付宝账号
  field :alipay_name, type: String #支付宝姓名

  field :wx_name, type: String, default: "" #微信实名制姓名(即微信绑定银行卡的姓名)
  field :openid, type: String, default: "" #转账唯一标示

  field :address, type: String, default: "" # 经营者地址1
  field :province, type: String, default: "" #省1
  field :city, type: String, default: "" #市区1
  field :district, type: String, default: "" #县、区1

  field :shopname, type: String # 经营者商店名称1
  field :location, type: Point, spatial: true, default: []
  field :email, type: String #邮箱 唯一

  field :status, type: Integer, default: 0 #启用状态，0初始化，1启用，-1禁用1

  field :integral, type: Integer, default: 0 # 积分
  field :approver, type: String #审批人
  field :pusher, type: String #推送人
  field :pusher_phone, type: String #推送人电话
  field :location_data, type: String #周围小B经纬度和配送距离

  # field :cash_pw,type: String #提现密码
  field :work_24, type: String, default: 'false' #24小时店 true／false

  field :alarm_stock, type: Integer, default: 10 # 预警库存数量1

  field :pdistance_state, type: Integer, default: 0 #0/1
  field :pdistance, type: Integer, default: 0 #配送距离
  field :pdistance_ask, type: Integer, default: 0
  field :fright_time, type: String #日间配送时间点
  field :night_time, type: String #夜间配送时间点
  field :fright, type: Integer, default: 0 # 运费1
  field :lowestprice, type: Integer, default: 0 # 最低起送价格1
  field :h_fright, type: Integer, default: 0 # 运费h
  field :h_lowestprice, type: Integer, default: 0 # 最低起送价格h
  field :start_business, type: String #营业开始时间
  field :end_business, type: String #营业结束时间
  field :channel_ids, type: Array, default: [] #移动设备推送IDs
  field :role_marks, type: Array, default: [] #角色标识 business: 运营商角色（对运营商），platform：平台角色（对平台）
  field :help_telephone, type: String, default: '' #客服热线
  field :achievesms_telephone,type: String, default: ''#接收推送信息的的手机号
  field :yqx_url, type: String, default: '' #易企秀url
  field :yqx_title, type: String, default: '' #易企秀标题
  field :yqx_desc, type: String, default: '' #易企秀描述
  field :share_desc, type: String, default: '' #易企秀描述

  #轮播图
  field :img_path1, type: String
  field :img_path2, type: String
  field :url1, type: String
  field :url2, type: String
  field :url3, type: String
  field :url4, type: String

  attr_readonly *fields.keys

  #是否为运营商
  def is_business

    self.role_marks.present? && self.role_marks.include?('business')
  end

  #是否为平台
  def is_platform

    self.role_marks.present? && self.role_marks.include?('platform')
  end

  def is_jxc
    self.role_marks.present? && self.role_marks.include?('jxc')
  end

  #是否为平台
  def self.get_platform

    Userinfo.find("56c45924c2fb4e205000000d")
  end


  #获取当前联盟商定位信息
  def get_location_info

    self.district.present? ? self.district : self.city
  end

end